<template>
  <div class="admin-dashboard">
    <!-- 顶部欢迎提示语 -->
    <div class="welcome-section">
      <h1 class="welcome-title">亲爱的{{ userInfo.name }}管理员，欢迎回到智慧养老中心管理系统！</h1>
      <p class="welcome-subtitle">用心管理，用爱服务，让养老中心运营更加高效和温暖 💼</p>
    </div>

    <!-- 数据概览 -->
    <div class="stats-section">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card class="stat-card">
            <div class="stat-content">
              <div class="stat-icon">👵</div>
              <div class="stat-info">
                <div class="stat-number">{{ stats.totalElder || 0 }}</div>
                <div class="stat-label">老人总数</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card">
            <div class="stat-content">
              <div class="stat-icon">🛏️</div>
              <div class="stat-info">
                <div class="stat-number">{{ stats.occupiedBed || 0 }}</div>
                <div class="stat-label">已占用床位</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card">
            <div class="stat-content">
              <div class="stat-icon">🆓</div>
              <div class="stat-info">
                <div class="stat-number">{{ stats.freeBed || 0 }}</div>
                <div class="stat-label">空闲床位</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card">
            <div class="stat-content">
              <div class="stat-icon">🍽️</div>
              <div class="stat-info">
                <div class="stat-number">{{ stats.todayMeal || 0 }}</div>
                <div class="stat-label">今日餐饮记录</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 管理功能模块 -->
    <div class="management-section">
      <h3 class="section-title">管理中心</h3>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-card class="management-card" @click="$router.push('/dashboard/admin/elder')">
            <div class="management-icon">👵</div>
            <h4>老人管理</h4>
            <p>管理老人信息、健康状况和入住情况</p>
            <div class="card-arrow">→</div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="management-card" @click="$router.push('/dashboard/admin/user')">
            <div class="management-icon">👥</div>
            <h4>员工管理</h4>
            <p>管理护工、前台等工作人员账号</p>
            <div class="card-arrow">→</div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="management-card" @click="$router.push('/dashboard/admin/medicine')">
            <div class="management-icon">💊</div>
            <h4>药品管理</h4>
            <p>管理药品库存和用药记录</p>
            <div class="card-arrow">→</div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="management-card" @click="$router.push('/dashboard/admin/meal')">
            <div class="management-icon">🍽️</div>
            <h4>餐饮管理</h4>
            <p>管理老人餐饮计划和营养搭配</p>
            <div class="card-arrow">→</div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="management-card" @click="$router.push('/dashboard/admin/accident')">
            <div class="management-icon">⚠️</div>
            <h4>事故管理</h4>
            <p>记录和处理各类意外事件</p>
            <div class="card-arrow">→</div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="management-card" @click="$router.push('/dashboard/admin/checkin')">
            <div class="management-icon">📋</div>
            <h4>入住管理</h4>
            <p>管理老人入住和退住流程</p>
            <div class="card-arrow">→</div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 系统公告 -->
    <div class="announcement-section">
      <el-card class="announcement-card">
        <template #header>
          <div class="announcement-header">
            <i class="el-icon-message"></i>
            <span>系统公告</span>
          </div>
        </template>
        <div class="announcement-content">
          <div class="announcement-item">
            <div class="announcement-title">📢 欢迎使用智慧养老中心管理系统</div>
            <div class="announcement-date">2025-09-30</div>
            <div class="announcement-text">
              感谢您选择我们的智慧养老中心管理系统。我们将持续优化系统功能，为您提供更好的管理体验。
            </div>
          </div>
          <div class="announcement-item">
            <div class="announcement-title">🌟 系统更新提醒</div>
            <div class="announcement-date">2025-09-28</div>
            <div class="announcement-text">
              系统已升级至最新版本，新增了多项实用功能，请及时了解更新内容。
            </div>
          </div>
        </div>
      </el-card>
    </div>

    <!-- 管理理念 -->
    <div class="philosophy-section">
      <el-card class="philosophy-card">
        <div class="philosophy-content">
          <div class="philosophy-text">
            <h3>管理理念</h3>
            <p>"作为养老中心的管理者，我们不仅是系统的操作者，更是温暖的传递者。每一个决策都关乎长者的幸福，每一次服务都承载着家属的信任。"</p>
            <div class="philosophy-principles">
              <div class="principle">
                <i class="el-icon-sunny"></i>
                <span>以人为本</span>
              </div>
              <div class="principle">
                <i class="el-icon-lock"></i>
                <span>安全第一</span>
              </div>
              <div class="principle">
                <i class="el-icon-medal"></i>
                <span>专业服务</span>
              </div>
              <div class="principle">
                <i class="el-icon-heart"></i>
                <span>爱心关怀</span>
              </div>
            </div>
          </div>
          <div class="philosophy-image">
            <div class="image-placeholder">
              <i class="el-icon-office-building"></i>
              <p>智慧养老中心</p>
            </div>
          </div>
        </div>
      </el-card>
    </div>

    <!-- 快速操作 -->
    <div class="quick-actions-section">
      <h3 class="section-title">快速操作</h3>
      <div class="quick-actions">
        <el-button type="primary" @click="$router.push('/dashboard/admin/elder')" size="large">
          <i class="el-icon-user"></i>
          老人管理
        </el-button>
        <el-button type="success" @click="$router.push('/dashboard/admin/user')" size="large">
          <i class="el-icon-user-solid"></i>
          员工管理
        </el-button>
        <el-button type="warning" @click="$router.push('/dashboard/admin/medicine')" size="large">
          <i class="el-icon-first-aid-kit"></i>
          药品管理
        </el-button>
        <el-button type="info" @click="$router.push('/dashboard/admin/meal')" size="large">
          <i class="el-icon-food"></i>
          餐饮管理
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, onMounted } from 'vue'
import axios from '@/api/axios'

// 用户信息
const userInfo = reactive(JSON.parse(localStorage.getItem('userInfo') || '{}'))

// 统计数据
const stats = reactive({
  totalElder: 0,
  occupiedBed: 0,
  freeBed: 0,
  todayMeal: 0
})

// 获取统计数据
const fetchStats = async () => {
  try {
    // 修改请求地址为管理员专用的统计数据接口
    const res = await axios.get('/admin/index/data')
    Object.assign(stats, res.data)
  } catch (e) {
    console.log('数据加载失败，使用默认值')
    // 设置默认值
    stats.totalElder = 25
    stats.occupiedBed = 20
    stats.freeBed = 5
    stats.todayMeal = 75
  }
}

onMounted(() => {
  fetchStats()
})
</script>

<style scoped>
.admin-dashboard {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  min-height: 100vh;
}

.welcome-section {
  text-align: center;
  margin-bottom: 40px;
  padding: 40px 20px;
  background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
  border-radius: 20px;
  color: white;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.welcome-title {
  font-size: 2.5em;
  margin-bottom: 15px;
  font-weight: 600;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.welcome-subtitle {
  font-size: 1.3em;
  opacity: 0.9;
  font-weight: 300;
}

.stats-section {
  margin-bottom: 40px;
}

.stat-card {
  border-radius: 15px;
  border: none;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  background: white;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
}

.stat-content {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px;
}

.stat-icon {
  font-size: 3em;
  width: 60px;
  text-align: center;
}

.stat-info {
  flex: 1;
}

.stat-number {
  font-size: 2.5em;
  font-weight: bold;
  color: #2c3e50;
  margin-bottom: 5px;
}

.stat-label {
  color: #7f8c8d;
  font-size: 0.9em;
  font-weight: 500;
}

.management-section {
  margin-bottom: 40px;
}

.section-title {
  color: #2c3e50;
  margin-bottom: 25px;
  font-size: 1.8em;
  font-weight: 600;
  text-align: center;
}

.management-card {
  border-radius: 15px;
  border: none;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  background: white;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
}

.management-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.management-card:hover h4,
.management-card:hover p {
  color: white;
}

.management-card:hover .management-icon {
  transform: scale(1.1);
}

.management-card:hover .card-arrow {
  opacity: 1;
  transform: translateX(5px);
}

.management-icon {
  font-size: 3em;
  margin-bottom: 15px;
  transition: all 0.3s ease;
}

.management-card h4 {
  color: #2c3e50;
  margin-bottom: 10px;
  font-size: 1.3em;
  font-weight: 600;
  transition: color 0.3s ease;
}

.management-card p {
  color: #7f8c8d;
  line-height: 1.5;
  margin-bottom: 15px;
  transition: color 0.3s ease;
}

.card-arrow {
  position: absolute;
  top: 20px;
  right: 20px;
  font-size: 1.5em;
  opacity: 0;
  transition: all 0.3s ease;
  color: white;
}

.announcement-section {
  margin-bottom: 40px;
}

.announcement-card {
  border-radius: 15px;
  border: none;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
  background: linear-gradient(135deg, #ffd89b 0%, #19547b 100%);
  color: white;
}

.announcement-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1.2em;
}

.announcement-header i {
  font-size: 1.3em;
}

.announcement-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.announcement-item {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  padding: 20px;
  color: #2c3e50;
}

.announcement-title {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 1.1em;
}

.announcement-date {
  color: #7f8c8d;
  font-size: 0.9em;
  margin-bottom: 10px;
}

.announcement-text {
  line-height: 1.5;
  color: #5d6d7e;
}

.philosophy-section {
  margin-bottom: 40px;
}

.philosophy-card {
  border-radius: 20px;
  border: none;
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.philosophy-content {
  display: flex;
  align-items: center;
  gap: 40px;
  padding: 30px;
}

.philosophy-text {
  flex: 1;
}

.philosophy-text h3 {
  color: #2d3436;
  margin-bottom: 20px;
  font-size: 1.8em;
  font-weight: 600;
}

.philosophy-text p {
  color: #2d3436;
  line-height: 1.6;
  margin-bottom: 25px;
  font-size: 1.1em;
  font-style: italic;
}

.philosophy-principles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.principle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.principle i {
  color: #74b9ff;
  font-size: 1.2em;
}

.principle span {
  color: #2d3436;
  font-weight: 500;
}

.philosophy-image {
  flex-shrink: 0;
  width: 200px;
}

.image-placeholder {
  width: 100%;
  height: 150px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #636e72;
  border: 2px dashed rgba(99, 110, 114, 0.3);
}

.image-placeholder i {
  font-size: 2em;
  margin-bottom: 10px;
}

.quick-actions-section {
  margin-bottom: 30px;
}

.quick-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.quick-actions .el-button {
  padding: 15px 25px;
  border-radius: 10px;
  font-weight: 500;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.quick-actions .el-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}
</style>
